package com.example.guetdemo.annotations.impl;

import com.example.guetdemo.constants.SystemConstants;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 状态标记校验器
 */
public class StrongPassword implements ConstraintValidator<com.example.guetdemo.annotations.StrongPassword,Object> {

    private String[] values;
    
    //初始化参数
    @Override
    public void initialize(com.example.guetdemo.annotations.StrongPassword strongPassword) {
        //根据用户填写的value值，来初始化此属性只支持的值!
        this.values = strongPassword.value();
    }

    /**
     * 强密码正则表达式校验
     * @param value
     * @param context
     * @return
     */
    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        String password = String.valueOf(value);
        if (password.matches(SystemConstants.STRONG_PASSWORD)) {
            return true;
        }
        return false;
    }

}